<?php

namespace app\admin\controller;

use app\common\controller\Backend;

use think\Controller;
use think\Request;
use think\Db;
use think\Log;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Articlecates extends Backend
{
    
    /**
     * ArticleCate模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('ArticleCate');
        $this->view->assign("typeList", $this->model->getTypeList());
        $this->view->assign("moduleTypeList", $this->model->getModuleTypeList());
        $this->view->assign("isOpenList", $this->model->getIsOpenList());
        $this->view->assign("isOpen1List", $this->model->getIsOpen1List());
    }

    public function add()
    {
        if ($this->request->isPost())
        {
            $this->code = -1;
            $params = $this->request->post("row/a");
            if ($params)
            {
                foreach ($params as $k => &$v)
                {
                    $v = is_array($v) ? implode(',', $v) : $v;
                }
                try
                {
                    //是否采用模型验证
                    if ($this->modelValidate)
                    {
                        $name = basename(str_replace('\\', '/', get_class($this->model)));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
                        $this->model->validate($validate);
                    }

                    $nowtime = time();
                    $timeby = date('Y-m-d H:i:s',$nowtime);
                    $params['input_time'] = $timeby;
                    $result = $this->model->save($params);
                    if ($result !== false)
                    {
                        $this->code = 1;
                    }
                    else
                    {
                        $this->msg = $this->model->getError();
                    }
                }
                catch (\think\exception\PDOException $e)
                {
                    $this->msg = $e->getMessage();
                }
            }
            else
            {
                $this->msg = __('Parameter %s can not be empty', '');
            }

            return;
        }
        return $this->view->fetch();
    }


    public function del($ids = "")
    {

        Log::record("dddddddd=".$ids);

        $this->code = -1;
        if ($ids)
        {
            $count = Db::name('article_cate')->where('id','in',$ids)->delete();
            if ($count)
            {
                $this->code = 1;
            }
        }

        return;
    }




    public function selectpage()
    {
        return parent::selectpage();
    }

}
